home *** CD-ROM | disk | FTP | other *** search
/ Light ROM 4 / Light ROM 4 - Disc 1.iso / text / net_news / 1994 / 1.doc / text0198.txt < prev    next >
Encoding:
Text File  |  1995-03-24  |  3.7 KB  |  159 lines

  1.  
  2. It seems from the group charter than small ARexx macros are fair game,
  3. so here is my humble contribution.  It is a modeler macro which makes
  4. gears, such as for bicycle chainrings and whatnot.
  5.  
  6. (Has anyone written a macro to make machine screws?  I'm looking for one
  7. of those so I don't have to write it myself :-) ).
  8.  
  9.   - steve
  10.  
  11. ~~~ cut here ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  12. /* CMD: Gear
  13.  * Make gears of user defined size in Modeler
  14.  * By Steve Koren Copyright © 1994 Steve Koren.
  15.  */
  16.  
  17. /* -- See if we have any parameters up front ------------------------------ */
  18.  
  19. arg name teeth rad_inner rad_outer thickness Ax
  20.  
  21. if name="" then name="Gear"
  22. else name=strip(name)
  23.  
  24. if teeth=""     then teeth=20
  25. if rad_inner="" then rad_inner=.4
  26. if rad_outer="" then rad_outer=.5
  27. if thickness="" then thickness=.1
  28. if Ax=""        then Ax='Y'
  29. cen = 0 0 0
  30. flist = Angular Smooth
  31.  
  32. /* -- Load proper function libraries -------------------------------------- */
  33.  
  34. signal on error
  35. signal on syntax
  36.  
  37. call addlib "rexxsupport.library", 0, -30, 0
  38. MATHLIB="rexxmathlib.library"
  39. IF POS(MATHLIB , SHOW('L')) = 0 THEN
  40.   IF ~ADDLIB(MATHLIB , 0 , -30 , 0) THEN DO
  41.         call notify(1,"!Can't find "MATHLIB)
  42.         exit
  43.         END
  44.  
  45. libadd = addlib("LWModelerARexx.port",0)
  46.  
  47.  
  48. /* -- Generate our requester ---------------------------------------------- */
  49.  
  50. call req_begin "Gear Generator"
  51.  
  52. AxId    = req_addcontrol("Axis", "CH",'X Y Z')
  53. TeethID = req_addcontrol("Teeth",'N')
  54. InnerID = req_addcontrol("Inner Radius",'N',1)
  55. OuterID = req_addcontrol("Outer Radius",'N',1)
  56. ThickID = req_addcontrol("Thickness",'N',1)
  57. TypeID  = req_addcontrol('Type:','CV',FList)
  58. CenID   = req_addcontrol("Center",'V',1)
  59. SurfId  = req_addcontrol("Surface",'R')
  60.  
  61. call req_setval AxId, 3
  62. call req_setval TeethID, 20,20
  63. call req_setval InnerID, 1,1
  64. call req_setval OuterID, 1.1,1.1
  65. call req_setval ThickID, .1,.1
  66. call req_setval CenID,0
  67. call req_setval TypeID,1
  68.  
  69. /* -- Post our requester and ask for input -------------------------------- */
  70.  
  71. if (~req_post()) then do
  72.     call req_end
  73.     exit
  74. end
  75.  
  76. teeth     = req_getval(TeethId)
  77. rad_inner = req_getval(InnerId)
  78. rad_outer = req_getval(OuterId)
  79. thickness = req_getval(ThickId)
  80. Ax        = req_getval(AxId)
  81. name      = req_getval(SurfId)
  82. cen       = req_getval(CenId)
  83. gtype     = req_getval(TypeID)
  84.  
  85. call req_end()
  86.  
  87. t_ang = 360.0 / teeth / 57.2957794
  88.  
  89. /* -- Generate a polygon -------------------------------------------------- */
  90.  
  91. vl=""
  92. cx = word(cen,1)
  93. cy = word(cen,2)
  94. cz = word(cen,3) - thickness/2
  95.  
  96. call ADD_BEGIN()
  97.   call SURFACE("___GEAR")
  98.  
  99.   do tooth=0 to teeth-1
  100.     a1  = t_ang * tooth
  101.     a2  = a1 + (t_ang*3/6)
  102.     a3  = a1 + (t_ang*4/6)
  103.     a4  = a1 + (t_ang*5/6)
  104.  
  105.     vl = vl add_point((rad_inner * sin(a1)+cx) (rad_inner * cos(a1)+cy) cz)
  106.     vl = vl add_point((rad_inner * sin(a2)+cx) (rad_inner * cos(a2)+cy) cz)
  107.     vl = vl add_point((rad_outer * sin(a3)+cx) (rad_outer * cos(a3)+cy) cz)
  108.     vl = vl add_point((rad_outer * sin(a4)+cx) (rad_outer * cos(a4)+cy) cz)
  109.  
  110.   end
  111.  
  112.   if gtype=2 then do
  113.     call ADD_CURVE vl
  114.     end
  115.   else do
  116.     call ADD_POLYGON vl
  117.     end
  118.  
  119. call ADD_END()
  120.  
  121. /* -- Make it part of the right surface ----------------------------------- */
  122.  
  123. call SEL_MODE(USER)
  124. call SEL_POLYGON(CLEAR, NVGT, 1)
  125. call SEL_POLYGON(SET,SURFACE, "___GEAR")
  126.  
  127. if gtype=2 then do
  128.   call FREEZECURVES()
  129. end
  130.  
  131. /* -- Generate proper thinkness ------------------------------------------- */
  132.  
  133. call EXTRUDE(Z, thickness, 1)
  134.  
  135. call CHANGESURFACE(name)
  136.  
  137. /* -- Rotate the new gear into the proper orientation --------------------- */
  138.  
  139. if Ax=1 then do       /* X */
  140.   call ROTATE(90, X, cen)
  141.   end
  142. else if Ax=2 then do  /* Y */
  143.   call ROTATE(90, Y, cen)
  144.   end
  145. else if Ax=3 then do  /* Z */
  146.   end
  147.  
  148.  
  149. exit
  150.  
  151. syntax:
  152. error:
  153.   call end_all
  154.     t=Notify(1,'!Rexx Script Error','@'ErrorText(rc),'Line 'SIGL)
  155.     exit
  156.  
  157.  
  158.  
  159.